﻿using IceDog.WebApi.MyTodo.Models;
using System;
using System.Linq;

namespace IceDog.WebApi.MyTodo.DBData
{
    /// <summary>
    /// 
    /// </summary>
    public class DbInitializer
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public static void Initialize(TodoContext context)
        {
            if (context.TodoItems.Any())
            {
                return;
            }
            var ran = new Random();
            context.TodoItems.Add(new TodoItem()
            {
                Name = "起床",
                Details = "早上起床",
                IsComplete = true,
                CreateTime = DateTime.Now.AddDays(ran.Next(1, 10)),
                CompleteTime = DateTime.Now.AddDays(ran.Next(10, 30))
            });
            context.TodoItems.Add(new TodoItem()
            {
                Name = "吃饭",
                Details = "早上吃饭",
                IsComplete = false,
                CreateTime = DateTime.Now.AddDays(ran.Next(1, 30)),
                CompleteTime = new DateTime()
            });
            context.TodoItems.Add(new TodoItem()
            {
                Name = "上班",
                Details = "滚去上班",
                IsComplete = false,
                CreateTime = DateTime.Now.AddDays(ran.Next(1, 30)),
                CompleteTime = new DateTime()
            });
            context.SaveChanges();
        }
    }
}
